#ifndef __THREAD_POOL_H__
#define __THREAD_POOL_H__

typedef void* (*THREAD_POOL_CB)(void *arg);

typedef struct _THREAD_POOL_JOB_s_
{
    THREAD_POOL_CB callback;
    void *arg;
    struct _THREAD_POOL_JOB_s_ *next;
}THREAD_POOL_JOB_s;

typedef struct _THREAD_POOL_s_
{
    INT32 thread_num;
    INT32 queue_max_num;
    THREAD_POOL_JOB_s *head;
    THREAD_POOL_JOB_s *tail;
    pthread_t *pthreads;
    pthread_mutex_t mutex;
    pthread_cond_t queue_empty;
    pthread_cond_t queue_not_empty;
    pthread_cond_t queue_not_full;
    INT32 queue_cur_num;
    INT32 queue_close;
    INT32 pool_close;
}THREAD_POOL_s;

extern THREAD_POOL_s* ThreadPool_init(INT32 thread_num, INT32 queue_max_num);
extern INT32 ThreadPool_add_job(THREAD_POOL_s *pool, THREAD_POOL_CB callback, void *arg);
extern INT32 ThreadPool_destroy(THREAD_POOL_s *pool);
extern void* ThreadPool_function(void* arg);

#endif

